<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>kickstarts 管理</title>
    {% load staticfiles %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">

    <link rel="stylesheet" href="{% static 'lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'lib/nprogress/nprogress.css' %}">
    <link rel="stylesheet" href="{% static 'css/scroll-bar.css' %}">
    <link rel="stylesheet" href="{% static 'css/sub-page.css' %}">
    {#    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_hsptnwurztv.css">#}


</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>系统推送</cite></a>
                <a><cite>ks管理</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>

    <!--工具栏-->
    <okToolbar>
        <button class="layui-btn" id="addChannel">
            <i class="layui-icon">&#xe61f;</i>添加kickstart启动文件
        </button>
        <span>共有推送数据：<i id="countNum"></i> 条</span>
    </okToolbar>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="{% static 'lib/layui/layui.js' %}"></script>
<script src="{% static 'lib/nprogress/nprogress.js' %}"></script>
<script>
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    };
    layui.use(['element', 'table', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#startTime',
            type: "datetime"
        });

        laydate.render({
            elem: '#endTime',
            type: "datetime"
        });

        table.render({
            elem: '#tableId',
            url: "{% url  'api_init_system_kickstart_get' %}",
            limit: 10,
            page: true,
            cols: [[
                {#{type: 'checkbox'},#}
                {field: 'kickstart', title: 'kickstart 路径', width: 500, sort: true},
                {field: 'status', title: '状态', width: 200,templet: '#statusTpl',},
                {title: '操作', width: 200, templet: '#operationTpl', align: 'center'},
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
            }
        });


        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'editkickstart') {
                layer.open({
                    title: '修改kickstart 文件',
                    type: 2,
                    maxmin: true,
                    shade: 0,
                    area: ['90%', '90%'],
                    content: "{% url 'edit-system-kickstarts' %}?kickstart="+data["kickstart"],
                    zIndex: layer.zIndex,
                    end: function () {
                        location.replace(location.href);
                        $(".layui-laypage-btn")[0].click();
                    }
                });
            } else if (layEvent === 'del') {
                layer.confirm("确定要删除吗？", {skin: 'layui-layer-lan', icon: 2, title: '提示', anim: 6}, function () {
                    $.ajax({
                        type: 'post',
                        url: "{% url 'api_init_system_kickstart_del' %}", // ajax请求路径
                        data: {
                            data: JSON.stringify(data),
                            csrfmiddlewaretoken: "{{ csrf_token }}",
                        },
                        dataType: 'json',
                        success: function (data) {
                            if (data["status"] == 0) {
                                layer.msg(data["message"], {icon: 6, time: 1000, anim: 4}, function () {
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    location.replace(location.href);
                                });
                            } else  {
                                layer.msg(data["message"]);
                            }
                        }
                    });

                });
            }
        });


        $("#addChannel").click(function () {
            layer.open({
                title: '添加 kickstart 文件',
                type: 2,
                maxmin: true,
                shade: 0.5, // 设置为0的时候，可以多开窗口，但是没有遮罩层了
                anim: 4,
                area: ['90%', '90%'],
                content: "{% url 'add-system-kickstarts' %}",
                zIndex: layer.zIndex,
                // skin: 'layui-layer-molv',
                end: function () {
                    $(".layui-laypage-btn")[0].click();
                }
            });
        })
    })
</script>
<!--模板-->
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" disabled value="{% verbatim %}{{d.id}}{% endverbatim %}" lay-skin="switch"
           lay-text="使用中的|没有使用" {% verbatim %}{{ d.status == "in-use" ? 'checked' : ''}}{% endverbatim %}>
</script>
<script type="text/html" id="clientTpl">
    {% verbatim %}{{ d.client == 0 ? '2D' : '3D    '}}{% endverbatim %}
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" title="修改" lay-event="editkickstart"><i class="layui-icon">&#xe628;</i></a>
    <a href="javascript:;" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
</body>
</html>